from assets.models import Asset, LOG
from transcodercaches.models import PreCacheRule

from assets.signals import asset_changed
 
      
class AssetJob(Asset):
  class Meta:
    proxy = True
  
  def transcode_cache(self):
    from damn import TranscoderInstance
    for format in PreCacheRule.objects.filter(srcFormats__id=self.format.id):
      kwargs = {}
      for arg in format.arguments.all():
        kwargs[arg.name] = arg.value
      LOG.info("Transcoding to %s with %s", format.dstFormat.name, str(kwargs))
      ref = Asset.objects.get_reference(id=self.id)
      path = TranscoderInstance().transcode(ref, format.dstFormat.name, **kwargs)
      LOG.info("file at %s", path)
